from sklearn.feature_extraction import DictVectorizer

data = [
  {'city':'北京','temperature':100},
  {'city':'上海','temperature':60},
  {'city':'深圳','temperature':40}
]
# 禁用稀疏矩阵
transfer = DictVectorizer(sparse=False)
data_new = transfer.fit_transform(data)
# 获取特征名称['city=上海', 'city=北京', 'city=深圳', 'temperature']
feature = transfer.get_feature_names()
print(data_new)
print(feature)

